package cn.vser.server.utils;

import java.io.Serializable;

public class SignParam implements Serializable {

    private static final long serialVersionUID = 2024706250490884667L;

    public static final String HEADER_VSER_VERSION = "VserVersion";
    public static final String HEADER_VSER_SDK_KEY = "VserSdkKey";
    public static final String HEADER_VSER_NONCE = "VserNonce";
    public static final String HEADER_VSER_TIMESTAMP = "VserTimestamp";
    public static final String HEADER_VSER_PATH = "VserPath";
    public static final String HEADER_VSER_SIGN_VERSION = "VserVserVersion";
    public static final String HEADER_VSER_SIGNATURE = "VserSignature";
    
    private String vserVersion;
    
    private String vserSdkKey;
    
    private String vserNonce;
    
    private Long vserTimestamp;
    
    private String vserPath;
    
    private String vserSignVersion;
    
    private String vserSignature;

    public String getVserVersion() {
        return vserVersion;
    }

    public void setVserVersion(String vserVersion) {
        this.vserVersion = vserVersion;
    }

    public String getVserSdkKey() {
        return vserSdkKey;
    }

    public void setVserSdkKey(String vserSdkKey) {
        this.vserSdkKey = vserSdkKey;
    }

    public String getVserNonce() {
        return vserNonce;
    }

    public void setVserNonce(String vserNonce) {
        this.vserNonce = vserNonce;
    }

    public Long getVserTimestamp() {
        return vserTimestamp;
    }

    public void setVserTimestamp(Long vserTimestamp) {
        this.vserTimestamp = vserTimestamp;
    }

    public String getVserPath() {
        return vserPath;
    }

    public void setVserPath(String vserPath) {
        this.vserPath = vserPath;
    }

    public String getVserSignVersion() {
        return vserSignVersion;
    }

    public void setVserSignVersion(String vserSignVersion) {
        this.vserSignVersion = vserSignVersion;
    }

    public String getVserSignature() {
        return vserSignature;
    }

    public void setVserSignature(String vserSignature) {
        this.vserSignature = vserSignature;
    }
    
    public static final String AND = "&";
    
    public String getSstring(String vserSdkSecret) {
        StringBuilder toSign = new StringBuilder();
        toSign.append(vserVersion).append(AND);
        toSign.append(vserSdkKey).append(AND);
        toSign.append(vserNonce).append(AND);
        toSign.append(vserTimestamp).append(AND);
        toSign.append(vserPath).append(AND);
        toSign.append(vserSignVersion).append(AND);
        toSign.append(vserSdkSecret);
        return toSign.toString();
    }
    
    public static SignParam build(String vserSdkKey, String vserPath) {
        SignParam signParam = new SignParam();
        signParam.setVserVersion("1.0");
        signParam.setVserSdkKey(vserSdkKey);
        signParam.setVserNonce(String.valueOf(Math.random() * 1000000));
        signParam.setVserTimestamp(System.currentTimeMillis());
        signParam.setVserPath(vserPath);
        signParam.setVserSignature("1.0");
        return signParam;
    }
}
